import {getInstance} from "./instance";
import type { Options } from "./model";
export const createMethods = (baseURL: string) => {
    const instance = getInstance(baseURL);
    if (!instance) {
        throw new Error('Axios instance not initialized. Call useAxios first.');
    }
    const Get = <T> (options:Options):T => instance({method:"GET",url:options.url,params:options.params,headers:{...options.headers},...options.others}) as unknown as T;
     const Put = <T> (options:Options):T => instance({method:"PUT",url:options.url,params:options.params,headers:{...options.headers},...options.others}) as unknown as T;
    const Delete = <T> (options:Options):T => instance({method:"DELETE",url:options.url,params:options.params,headers:{...options.headers},...options.others}) as unknown as T;
    const Post = <T> (options:Options):T => instance({method:"POST",url:options.url,data:options.params,headers:{...options.headers},...options.others}) as unknown as T;

    return {
        Delete,
        Post,
        Get,
        Put,
    }
}